<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="专业市场名称" prop="marketName">
        <el-input v-model="queryParams.marketName" placeholder="请输入专业市场名称" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="客户名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入客户名称" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="证件号码" prop="idCard">
        <el-input v-model="queryParams.idCard" placeholder="请输入证件号码" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="机构号" prop="orgId">
        <el-select v-model="queryParams.orgId" placeholder="请选择机构号" clearable size="small">
          <el-option
            v-for="dict in orgIdOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="客户经理号" prop="managerId">
        <el-select v-model="queryParams.managerId" placeholder="请选择客户经理号" clearable size="small">
          <el-option
            v-for="dict in managerIdOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['buss:zyscKh:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['buss:zyscKh:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['buss:zyscKh:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['buss:zyscKh:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="zyscKhList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="是否购买农业保险(1是0否)" align="center" prop="id" />
      <el-table-column label="专业市场ID" align="center" prop="marketId" />
      <el-table-column label="专业市场名称" align="center" prop="marketName" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="身份证" align="center" prop="idCard" />
      <el-table-column label="经营地址" align="center" prop="runAddress" />
      <el-table-column label="地址定位" align="center" prop="dwAddress" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="客户类型" align="center" prop="khlx" :formatter="khlxFormat" />
      <el-table-column label="群体标签" align="center" prop="qtbq" />
      <el-table-column label="所属行业" align="center" prop="sshy" />
      <el-table-column label="经营状况" align="center" prop="jyzk" />
      <el-table-column label="真实经度" align="center" prop="zhenshiJingdu"/>
      <el-table-column label="真实纬度" align="center" prop="zhenshiWeidu"/>
      <el-table-column label="法定代表人" align="center" prop="fddbr"/>
      <el-table-column label="代表人证件号码" align="center" prop="dbrZjhm" />
      <el-table-column label="实际经营人" align="center" prop="sjjyr" />
      <el-table-column label="实际经营人证件号码" align="center" prop="jjrZjhm" />
      <el-table-column label="是否拓展客户 0否 1是" align="center" prop="isExpand" :formatter="isExpandFormat" />
      <el-table-column label="商户注册名称" align="center" prop="shzcmc"  />
      <el-table-column label="对公对私" align="center" prop="dgds" />
      <el-table-column label="机构名称" align="center" prop="orgId" :formatter="orgIdFormat" />
      <el-table-column label="客户经理名称" align="center" prop="managerId" :formatter="managerIdFormat" />
      <el-table-column label="备注" align="center" prop="remark"  />
      <el-table-column label="是否删除" align="center" prop="delFlag" :formatter="delFlagFormat" />
      <el-table-column label="创建时间" align="center" prop="createTime"  />
      <el-table-column label="创建人" align="center" prop="createUser" />
      <el-table-column label="修改时间" align="center" prop="updateTime"  />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['buss:zyscKh:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['buss:zyscKh:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改专业市场客户对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="专业市场ID" prop="marketId">
          <el-input v-model="form.marketId" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="专业市场名称" prop="marketName">
          <el-input v-model="form.marketName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="身份证" prop="idCard">
          <el-input v-model="form.idCard" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="经营地址" prop="runAddress">
          <el-input v-model="form.runAddress" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="地址定位" prop="dwAddress">
          <el-input v-model="form.dwAddress" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="客户类型" prop="khlx">
          <el-select v-model="form.khlx" placeholder="请选择客户类型">
            <el-option
              v-for="dict in khlxOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="群体标签" prop="qtbq">
          <el-select v-model="form.qtbq" placeholder="请选择群体标签">
            <el-option
              v-for="dict in qtbqOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属行业" prop="sshy">
          <el-select v-model="form.sshy" placeholder="请选择所属行业">
            <el-option
              v-for="dict in sshyOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="经营状况" prop="jyzk">
          <el-select v-model="form.jyzk" placeholder="请选择经营状况">
            <el-option
              v-for="dict in jyzkOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="法定代表人" prop="fddbr">
          <el-input v-model="form.fddbr" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="代表人证件号码" prop="dbrZjhm">
          <el-input v-model="form.dbrZjhm" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="实际经营人" prop="sjjyr">
          <el-input v-model="form.sjjyr" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="实际经营人证件号码" prop="jjrZjhm">
          <el-input v-model="form.jjrZjhm" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否拓展客户 0否 1是" prop="isExpand">
          <el-select v-model="form.isExpand" placeholder="请选择是否拓展客户 0否 1是">
            <el-option
              v-for="dict in isExpandOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商户注册名称" prop="shzcmc">
          <el-input v-model="form.shzcmc" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="对公对私0对私1对公" prop="dgds">
          <el-select v-model="form.dgds" placeholder="请选择对公对私0对私1对公">
            <el-option
              v-for="dict in dgdsOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="机构号" prop="orgId">
          <el-select v-model="form.orgId" placeholder="请选择机构号">
            <el-option
              v-for="dict in orgIdOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户经理号" prop="managerId">
          <el-select v-model="form.managerId" placeholder="请选择客户经理号">
            <el-option
              v-for="dict in managerIdOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否删除" prop="delFlag">
          <el-select v-model="form.delFlag" placeholder="请选择是否删除">
            <el-option
              v-for="dict in delFlagOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listZyscKh, getZyscKh, delZyscKh, addZyscKh, updateZyscKh } from "@/api/buss/zyscKh";

export default {
  name: "ZyscKh",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专业市场客户表格数据
      zyscKhList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,



      // 客户类型 1 普通客户 2 潜在客户 3重点客户字典
      khlxOptions: [],


      isExpandOptions: [],

      // 机构号字典
      orgIdOptions: [],

      // 客户经理号字典
      managerIdOptions: [],


      // 是否删除字典
      delFlagOptions: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        marketId: null,
        marketName: null,
        name: null,
        idCard: null,
        runAddress: null,
        dwAddress: null,
        phone: null,
        khlx: null,
        qtbq: null,
        sshy: null,
        jyzk: null,
        zhenshiJingdu: null,
        zhenshiWeidu: null,
        fddbr: null,
        dbrZjhm: null,
        sjjyr: null,
        jjrZjhm: null,
        isExpand: null,
        shzcmc: null,
        dgds: null,
        orgId: null,
        orgName: null,
        managerId: null,
        userName: null,
        remark: null,
        delFlag: null,
        createTime: null,
        createUser: null,
        updateTime: null,
        importType: null,
        ncjylx: null,
        gdmj: null,
        zlmj: null,
        ldmj: null,
        cdmj: null,
        smmj: null,
        qttdqk: null,
        ndzsr: null,
        sfnc: null,
        sfgszc: null,
        sfzcsb: null,
        sfnybx: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();



    this.getDicts("type").then(response => {
      this.khlxOptions = response.data;
    });
    this.getDicts("if_yes_no").then(response => {
      this.isExpandOptions = response.data;
    });
    this.getDicts("sys_org_id").then(response => {
      this.orgIdOptions = response.data;
    });
    this.getDicts("sys_user_id").then(response => {
      this.managerIdOptions = response.data;
    });
    this.getDicts("if_yes_no").then(response => {
      this.delFlagOptions = response.data;
    });
  },
  methods: {
    /** 查询专业市场客户列表 */
    getList() {
      this.loading = true;
      listZyscKh(this.queryParams).then(response => {
        this.zyscKhList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 是否购买农业保险(1是0否)字典翻译
    idFormat(row, column) {
      return this.selectDictLabel(this.idOptions, row.id);
    },
    // 专业市场ID字典翻译
    marketIdFormat(row, column) {
      return this.selectDictLabel(this.marketIdOptions, row.marketId);
    },
    // 专业市场名称字典翻译
    marketNameFormat(row, column) {
      return this.selectDictLabel(this.marketNameOptions, row.marketName);
    },
    // 姓名字典翻译
    nameFormat(row, column) {
      return this.selectDictLabel(this.nameOptions, row.name);
    },
    // 身份证字典翻译
    idCardFormat(row, column) {
      return this.selectDictLabel(this.idCardOptions, row.idCard);
    },
    // 经营地址字典翻译
    runAddressFormat(row, column) {
      return this.selectDictLabel(this.runAddressOptions, row.runAddress);
    },
    // 地址定位字典翻译
    dwAddressFormat(row, column) {
      return this.selectDictLabel(this.dwAddressOptions, row.dwAddress);
    },
    // 电话字典翻译
    phoneFormat(row, column) {
      return this.selectDictLabel(this.phoneOptions, row.phone);
    },
    // 客户类型 1 普通客户 2 潜在客户 3重点客户字典翻译
    khlxFormat(row, column) {
      return this.selectDictLabel(this.khlxOptions, row.khlx);
    },
    // 群体标签(1区财政2地方财政3政府专项4村级资金5行政事业单位6学校7医院8粮管所9一般对公户10个体工商户11教师12医护13公职人员14外出务工户15种植大户16养殖大户17城镇职工18)字典翻译
    qtbqFormat(row, column) {
      return this.selectDictLabel(this.qtbqOptions, row.qtbq);
    },
    // 所属行业字典翻译
    sshyFormat(row, column) {
      return this.selectDictLabel(this.sshyOptions, row.sshy);
    },
    // 经营状况字典翻译
    jyzkFormat(row, column) {
      return this.selectDictLabel(this.jyzkOptions, row.jyzk);
    },
    // 真实经度字典翻译
    zhenshiJingduFormat(row, column) {
      return this.selectDictLabel(this.zhenshiJingduOptions, row.zhenshiJingdu);
    },
    // 真实纬度字典翻译
    zhenshiWeiduFormat(row, column) {
      return this.selectDictLabel(this.zhenshiWeiduOptions, row.zhenshiWeidu);
    },
    // 法定代表人字典翻译
    fddbrFormat(row, column) {
      return this.selectDictLabel(this.fddbrOptions, row.fddbr);
    },
    // 代表人证件号码字典翻译
    dbrZjhmFormat(row, column) {
      return this.selectDictLabel(this.dbrZjhmOptions, row.dbrZjhm);
    },
    // 实际经营人字典翻译
    sjjyrFormat(row, column) {
      return this.selectDictLabel(this.sjjyrOptions, row.sjjyr);
    },
    // 实际经营人证件号码字典翻译
    jjrZjhmFormat(row, column) {
      return this.selectDictLabel(this.jjrZjhmOptions, row.jjrZjhm);
    },
    // 是否拓展客户 0否 1是字典翻译
    isExpandFormat(row, column) {
      return this.selectDictLabel(this.isExpandOptions, row.isExpand);
    },
    // 商户注册名称字典翻译
    shzcmcFormat(row, column) {
      return this.selectDictLabel(this.shzcmcOptions, row.shzcmc);
    },
    // 对公对私0对私1对公字典翻译
    dgdsFormat(row, column) {
      return this.selectDictLabel(this.dgdsOptions, row.dgds);
    },
    // 机构号字典翻译
    orgIdFormat(row, column) {
      return this.selectDictLabel(this.orgIdOptions, row.orgId);
    },
    // 机构名称字典翻译
    orgNameFormat(row, column) {
      return this.selectDictLabel(this.orgNameOptions, row.orgName);
    },
    // 客户经理号字典翻译
    managerIdFormat(row, column) {
      return this.selectDictLabel(this.managerIdOptions, row.managerId);
    },
    // 客户经理名称字典翻译
    userNameFormat(row, column) {
      return this.selectDictLabel(this.userNameOptions, row.userName);
    },
    // 备注字典翻译
    remarkFormat(row, column) {
      return this.selectDictLabel(this.remarkOptions, row.remark);
    },
    // 是否删除字典翻译
    delFlagFormat(row, column) {
      return this.selectDictLabel(this.delFlagOptions, row.delFlag);
    },
    // 创建时间字典翻译
    createTimeFormat(row, column) {
      return this.selectDictLabel(this.createTimeOptions, row.createTime);
    },
    // 创建人字典翻译
    createUserFormat(row, column) {
      return this.selectDictLabel(this.createUserOptions, row.createUser);
    },
    // 修改时间字典翻译
    updateTimeFormat(row, column) {
      return this.selectDictLabel(this.updateTimeOptions, row.updateTime);
    },
    // 1 批量导入(信息可能不全,不对,待客户经理进入APP修改)字典翻译
    importTypeFormat(row, column) {
      return this.selectDictLabel(this.importTypeOptions, row.importType);
    },
    // 农场经营类型字典翻译
    ncjylxFormat(row, column) {
      return this.selectDictLabel(this.ncjylxOptions, row.ncjylx);
    },
    // 耕地面积字典翻译
    gdmjFormat(row, column) {
      return this.selectDictLabel(this.gdmjOptions, row.gdmj);
    },
    // 种粮面积字典翻译
    zlmjFormat(row, column) {
      return this.selectDictLabel(this.zlmjOptions, row.zlmj);
    },
    // 林地面积字典翻译
    ldmjFormat(row, column) {
      return this.selectDictLabel(this.ldmjOptions, row.ldmj);
    },
    // 草地面积字典翻译
    cdmjFormat(row, column) {
      return this.selectDictLabel(this.cdmjOptions, row.cdmj);
    },
    // 水面面积字典翻译
    smmjFormat(row, column) {
      return this.selectDictLabel(this.smmjOptions, row.smmj);
    },
    // 其他土地情况字典翻译
    qttdqkFormat(row, column) {
      return this.selectDictLabel(this.qttdqkOptions, row.qttdqk);
    },
    // 年度总收入字典翻译
    ndzsrFormat(row, column) {
      return this.selectDictLabel(this.ndzsrOptions, row.ndzsr);
    },
    // 示范农场(0-否;1-县级示范农场;2-市级示范农场;3-省级示范农场)字典翻译
    sfncFormat(row, column) {
      return this.selectDictLabel(this.sfncOptions, row.sfnc);
    },
    // 是否在工商局注册(0-否,1-是)字典翻译
    sfgszcFormat(row, column) {
      return this.selectDictLabel(this.sfgszcOptions, row.sfgszc);
    },
    // 是否有注册商标(1是0否)字典翻译
    sfzcsbFormat(row, column) {
      return this.selectDictLabel(this.sfzcsbOptions, row.sfzcsb);
    },
    // 是否购买农业保险(1是0否)字典翻译
    sfnybxFormat(row, column) {
      return this.selectDictLabel(this.sfnybxOptions, row.sfnybx);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        marketId: null,
        marketName: null,
        name: null,
        idCard: null,
        runAddress: null,
        dwAddress: null,
        phone: null,
        khlx: null,
        qtbq: null,
        sshy: null,
        jyzk: null,
        zhenshiJingdu: null,
        zhenshiWeidu: null,
        fddbr: null,
        dbrZjhm: null,
        sjjyr: null,
        jjrZjhm: null,
        isExpand: null,
        shzcmc: null,
        dgds: null,
        orgId: null,
        orgName: null,
        managerId: null,
        userName: null,
        remark: null,
        delFlag: null,
        createTime: null,
        createUser: null,
        updateTime: null,
        importType: null,
        ncjylx: null,
        gdmj: null,
        zlmj: null,
        ldmj: null,
        cdmj: null,
        smmj: null,
        qttdqk: null,
        ndzsr: null,
        sfnc: null,
        sfgszc: null,
        sfzcsb: null,
        sfnybx: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加专业市场客户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getZyscKh(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改专业市场客户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateZyscKh(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addZyscKh(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除专业市场客户编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delZyscKh(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('buss/zyscKh/export', {
        ...this.queryParams
      }, `buss_zyscKh.xlsx`)
    }
  }
};
</script>
